package com.matrix.draft.sockettest.day1;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws Exception {
        ServerSocket server = new ServerSocket(8080);
        System.out.println("ServerSocket 8080已启动...");

        while (true) {
            // 等待一个连接
            Socket socket = server.accept();
            System.err.println(socket.getInetAddress().getHostName()+"连接成功");
            BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String msg;
            while ((msg=br.readLine())!=null) {
                System.out.println("Msg from client: " + msg);
                Thread.sleep(5000);
            }
        }
    }
}
